package com.dengyiming.search.web;

import com.dengyiming.common.dto.PageDTO;
import com.dengyiming.search.pojo.ItemDoc;
import com.dengyiming.search.pojo.SearchDTO;
import com.dengyiming.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 分页查询
     * @param searchDTO
     * @return
     */
    @PostMapping("list")
    public PageDTO<ItemDoc> searchList(@RequestBody SearchDTO searchDTO) throws IOException {
        log.info("查询的数据：{}",searchDTO);
        return searchService.searchList(searchDTO);
    }
    @PostMapping("filters")
    public Map<String, List<String>> searchFilters(@RequestBody SearchDTO searchDTO){
        log.info("查询的数据：{}",searchDTO);
        return searchService.searchFilters(searchDTO);
    }
    @GetMapping("suggestion")
    public List<String> searchSuggestion(@RequestParam(value = "key") String key){
        return searchService.searchSuggestion(key);
    }
}
